bitkeeper revision 1.263 (3f044553Casub9OwqMoobhkY4qWGpQ)
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Thu, 3 Jul 2003 15:01:39 +0000 (15:01 +0000)
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Thu, 3 Jul 2003 15:01:39 +0000 (15:01 +0000)
Apply Composite pattern to add recursive command parsing; this allows commands to be in groups so that the user interface isn't quite so unwieldy.
In order to make this sensible, rename the domain classes to indicate better what they are.

25 files changed:
.rootkeys
tools/control/src/org/xenoserver/cmdline/CommandParser.java
tools/control/src/org/xenoserver/cmdline/Main.java
tools/control/src/org/xenoserver/cmdline/ParseDestroy.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseDomainList.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseGroup.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseHelp.java
tools/control/src/org/xenoserver/cmdline/ParseList.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseNew.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseStart.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseStop.java [deleted file]
tools/control/src/org/xenoserver/control/CommandDestroy.java [deleted file]
tools/control/src/org/xenoserver/control/CommandDomainDestroy.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandDomainList.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandDomainNew.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandDomainStart.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandDomainStop.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandList.java [deleted file]
tools/control/src/org/xenoserver/control/CommandNew.java [deleted file]
tools/control/src/org/xenoserver/control/CommandStart.java [deleted file]
tools/control/src/org/xenoserver/control/CommandStop.java [deleted file]

index 2938a7a6f30ce44a570783fd3b95aaba25edc34d..ce245516ba5d2d0d45d8a8e3627f2e7c0cfeb3ff 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 3eb781fcabCKRogwxJA3-jJKstw9Vg tools/control/domctl.xml
 3f042c35FzVap5QW0UBPnZ2ZM0l3QA tools/control/src/org/xenoserver/cmdline/CommandParser.java
 3eb781fdNQvEJW3tNvovjqoN7GlePA tools/control/src/org/xenoserver/cmdline/Main.java
-3f042c35-TPgpCQViIaJzLts2-CnBw tools/control/src/org/xenoserver/cmdline/ParseDestroy.java
+3f042c35-TPgpCQViIaJzLts2-CnBw tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java
+3f042c35h9GAWRu7wimPjBpCi09nUA tools/control/src/org/xenoserver/cmdline/ParseDomainList.java
+3f042c359mRNaxBYXFwVsmv5-J_DJA tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java
+3f042c35bMvqLB4Yc-0Dxs4WlYHHpw tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java
+3f042c35Lc-JegNavF6Bj6coM486Ig tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java
 3f042c35UhRkvblwKSx0KW2QHUn3Fw tools/control/src/org/xenoserver/cmdline/ParseFailedException.java
+3f0445524oTSyogDGmCAyKMM665Rxg tools/control/src/org/xenoserver/cmdline/ParseGroup.java
 3f042c35Inw0LzkOzXo9ncbEHZzUHA tools/control/src/org/xenoserver/cmdline/ParseHelp.java
-3f042c35h9GAWRu7wimPjBpCi09nUA tools/control/src/org/xenoserver/cmdline/ParseList.java
-3f042c359mRNaxBYXFwVsmv5-J_DJA tools/control/src/org/xenoserver/cmdline/ParseNew.java
-3f042c35bMvqLB4Yc-0Dxs4WlYHHpw tools/control/src/org/xenoserver/cmdline/ParseStart.java
-3f042c35Lc-JegNavF6Bj6coM486Ig tools/control/src/org/xenoserver/cmdline/ParseStop.java
 3f042c35V-Bf3dlIe1r5mZs8ZTPSvA tools/control/src/org/xenoserver/control/Command.java
-3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDestroy.java
+3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDomainDestroy.java
+3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandDomainList.java
+3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/control/src/org/xenoserver/control/CommandDomainNew.java
+3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandDomainStart.java
+3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandDomainStop.java
 3f042c35hdwL__Airzyz4HutOgGRqQ tools/control/src/org/xenoserver/control/CommandFailedException.java
-3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandList.java
-3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/control/src/org/xenoserver/control/CommandNew.java
-3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandStart.java
-3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandStop.java
 3eb781fdBRXfSlWzK6GXlIQIlHFoaQ tools/control/src/org/xenoserver/control/Defaults.java
 3ec41f7cQ7Ug739JBDrsVH-7KJ5MvQ tools/control/src/org/xenoserver/control/Domain.java
 3eb781fdDeZEopemXIVg_ARCGKSmBw tools/control/src/org/xenoserver/control/InetAddressPattern.java
index 3f4fc85032c565a321c5e162bf064fb7a12b55c8..e5dc21b6582e2940be36183432c0e9988c72a1e9 100644 (file)
@@ -1,5 +1,9 @@
 package org.xenoserver.cmdline;
 
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
 import org.xenoserver.control.Command;
 import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
@@ -20,51 +24,64 @@ public abstract class CommandParser {
    * @throws ParseFailedException if the arguments are not suitable.
    * @throws CommandFailedException if the command did not execute successfully.
    */
-  public abstract void parse(Defaults d, String args[]) throws ParseFailedException, CommandFailedException;
+  public abstract void parse(Defaults d, LinkedList args)
+    throws ParseFailedException, CommandFailedException;
 
-  /** Return the command name which will be matched on the command line. */  
-  public abstract String getName();     
+  /** Return the command name which will be matched on the command line. */
+  public abstract String getName();
   /** Return a usage string for this command. */
   public abstract String getUsage();
   /** Return the help text for this command. */
   public abstract String getHelpText();
-
-  public String getStringParameter(String args[], char key, String def)
+  
+  /** Print a usage string for this command. */
+  public void printUsage(String prefix)
+  {
+    String name = getName();
+    if ( prefix != null )
+      name = prefix + " " + name;
+    String usage = getUsage();
+    while (name.length() < 16)
+      name = name + " ";
+    System.out.println("   " + name + usage);
+  }
+  
+  /** Prints the help text for this command. */
+  public void printHelpText(LinkedList args)
   {
-    String r = getParameter (args, key);
+    System.out.println(getName() + " " + getUsage());
+    System.out.println();
+    System.out.println(getHelpText());
+  }
+
+  public String getStringParameter(List args, char key, String def) {
+    String r = getParameter(args, key);
     return (r == null) ? def : r;
   }
 
-  public int getIntParameter(String args[], char key, int def)
-  {
-    String r = getParameter (args, key);
-    return (r == null) ? def : (Integer.parseInt (r));
+  public int getIntParameter(List args, char key, int def) {
+    String r = getParameter(args, key);
+    return (r == null) ? def : (Integer.parseInt(r));
   }
 
-  public boolean getFlagParameter(String args[], char key)
-  {
-    String r = getParameter (args, key);
+  public boolean getFlagParameter(List args, char key) {
+    String r = getParameter(args, key);
     return (r == null) ? false : true;
   }
 
-  protected String getParameter (String args[], char key)
-  {
-    int i;
+  protected String getParameter(List args, char key) {
     String result = null;
-    for (i = 0; i < args.length; i ++)
-      {
-  if (args[i].startsWith("-" + key)) 
-    {
-      if (args[i].length() > 2)
-        {
-    result = args[i].substring(2, args[i].length());
+    Iterator i = args.iterator();
+    while ( i.hasNext() ) {
+      String arg = (String) i.next();
+      if (arg.startsWith("-" + key)) {
+        if (arg.length() > 2) {
+          result = arg.substring(2);
+        } else {
+          result = "";
         }
-      else
-        {
-    result = "";
-        }
-    }
       }
+    }
     return result;
   }
 }
index a85c1923a7864f393b1d91b892d481642f1c9874..b21aba57b311b101114cc3541d2a40e031140819 100644 (file)
@@ -1,46 +1,46 @@
 package org.xenoserver.cmdline;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
 import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
 
 public class Main {
-  private static ParseHelp help = new ParseHelp();
-  static CommandParser commands[] =
+  static final ParseHelp help = new ParseHelp();
+  static final CommandParser domaincommands[] =
+    { new ParseDomainNew(),
+      new ParseDomainStart(),
+      new ParseDomainStop(),
+      new ParseDomainDestroy(),
+      new ParseDomainList()
+    };
+  static final CommandParser commands[] =
     { help,
-      new ParseNew(),
-      new ParseStart(),
-      new ParseStop(),
-      new ParseDestroy(),
-      new ParseList() };
+      new ParseGroup( "domain", domaincommands )
+    };
+  static final CommandParser parser = new ParseGroup( null, commands );
 
   public static void main(String[] args) {
     Defaults d = new Defaults();
     int ec = -1;
+    LinkedList arglist = new LinkedList();
+    for ( int i=0; i<args.length; i++ )
+      arglist.add( args[i] );
 
     if (args.length == 0) {
-      help.parse(d, args);
+      help.parse(d, arglist);
     } else {
-      String c = args[0];
-      int i;
-      for (i = 0; i < commands.length; i++) {
-        if (commands[i].getName().equals(c)) {
-          if (commands[i].getFlagParameter(args, '?')) {
-            help.doHelpFor(commands[i]);
-          } else {
-            try {
-              commands[i].parse(d, args);
-              ec = 0;
-            } catch (ParseFailedException e) {
-              System.err.println( e.getMessage() );
-            } catch (CommandFailedException e) {
-              System.err.println( e.getMessage() );
-            }
-          }
-          break;
-        }
-      }
-      if (i == commands.length) {
-        System.out.println("Unknown command " + c);
+      try
+      {
+        parser.parse(d, arglist);
+        ec = 0;
+      } catch (ParseFailedException e) {
+        System.err.println( e.getMessage() );
+      } catch (CommandFailedException e) {
+        System.err.println( e.getMessage() );
       }
     }
 
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDestroy.java b/tools/control/src/org/xenoserver/cmdline/ParseDestroy.java
deleted file mode 100644 (file)
index 4368c9d..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.xenoserver.cmdline;
-
-import org.xenoserver.control.Command;
-import org.xenoserver.control.CommandDestroy;
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.Defaults;
-
-public class ParseDestroy extends CommandParser {
-  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    boolean force = getFlagParameter(args, 'f');
-
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
-    }
-
-    String output = new CommandDestroy(d, domain_id, force).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-  
-  public String getName()
-  {
-    return "destroy";
-  }
-
-  public String getUsage()
-  {
-    return "[-f] [-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Destory the specified domain.  -f forcibly destroys it.";
-  }
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java
new file mode 100644 (file)
index 0000000..ffbe324
--- /dev/null
@@ -0,0 +1,40 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.Command;
+import org.xenoserver.control.CommandDomainDestroy;
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.Defaults;
+
+public class ParseDomainDestroy extends CommandParser {
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    int domain_id = getIntParameter(args, 'n', 0);
+    boolean force = getFlagParameter(args, 'f');
+
+    if (domain_id == 0) {
+      throw new ParseFailedException("Expected -n<domain_id>");
+    }
+
+    String output = new CommandDomainDestroy(d, domain_id, force).execute();
+    if ( output != null )
+      System.out.println( output );
+  }
+  
+  public String getName()
+  {
+    return "destroy";
+  }
+
+  public String getUsage()
+  {
+    return "[-f] [-n<domain_id>]";
+  }
+
+  public String getHelpText()
+  {
+    return
+      "Destory the specified domain.  -f forcibly destroys it.";
+  }
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java
new file mode 100644 (file)
index 0000000..193d5ac
--- /dev/null
@@ -0,0 +1,49 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.Command;
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandDomainList;
+import org.xenoserver.control.Defaults;
+import org.xenoserver.control.Domain;
+
+public class ParseDomainList extends CommandParser {
+
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    CommandDomainList list = new CommandDomainList(d);
+    String output = list.execute();
+    if ( output != null )
+      System.out.println( output );
+    Domain[] domains = list.domains();
+
+    for (int loop = 0; loop < domains.length; loop++)
+    {
+      System.out.println ("id: " + domains[loop].id + 
+        " (" + domains[loop].name+ ")");
+      System.out.println ("  processor: " + domains[loop].processor);
+      System.out.println ("  has cpu: " + domains[loop].cpu);
+      System.out.println ("  state: " + domains[loop].nstate + " " +
+        domains[loop].state);
+      System.out.println ("  mcu advance: " + domains[loop].mcu);
+      System.out.println ("  total pages: " + domains[loop].pages);
+    }
+  }
+
+  public String getName()
+  {
+    return "list";
+  }
+
+  public String getUsage()
+  {
+    return "";
+  }
+
+  public String getHelpText()
+  {
+    return
+      "List domain information";
+  }
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java
new file mode 100644 (file)
index 0000000..bab3778
--- /dev/null
@@ -0,0 +1,84 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.Command;
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandDomainNew;
+import org.xenoserver.control.Defaults;
+
+public class ParseDomainNew extends CommandParser {
+
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    String name = getStringParameter(args, 'n', d.domainName);
+    int size = getIntParameter(args, 'k', d.domainSizeKB);
+    String image = getStringParameter(args, 'i', d.domainImage);
+    String initrd = getStringParameter (args, 'r', d.domainInitRD);
+    int vifs = getIntParameter(args, 'v', d.domainVIFs);
+    String bargs = getStringParameter (args, 'a', d.args) + " ";
+    String root_dev = getStringParameter (args, 'd', d.rootDevice);
+    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
+    String nw_ip = getStringParameter (args, '4', d.NWIP);
+    String nw_gw = getStringParameter (args, 'g', d.NWGW);
+    String nw_mask = getStringParameter (args, 'm', d.NWMask);
+    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
+    String nw_host = getStringParameter (args, 'h', d.NWHost);
+
+    d.describe();
+
+    CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs,
+                                  bargs, root_dev, nfs_root_path,
+                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
+    c.execute();
+    String[] output = c.output();
+    for ( int i = 0; i < output.length; i++ )
+      System.out.println( output[i] ); 
+  }
+
+  public String getName()
+  {
+    return "new";
+  }
+
+  public String getUsage()
+  {
+    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
+  }
+
+  public String getHelpText()
+  {
+    return
+      "Create a new domain.  Note that most of the parameters will assume\n" +
+      "default values: it should not be necessary to specify them all. See\n" +
+      "domctl.xml for the current default settings.\n" +
+      "\n" +
+      "General command line options:\n" +
+      "  -n  Domain name                              domain_name\n" +
+      "  -k  Domain size (kb)                         domain_size_kb\n" +
+      "  -i  Domain image name                        domain_image\n" +
+      "  -v  Number of VIFs                           domain_vifs\n" +
+      "  -r  InitRD (if required)                     domain_init_rd\n" +
+      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
+      "  -a  Additional boot parameters\n" +
+      "\n" +
+      "Networking options:\n" +
+      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
+      "  -s  NFS server                               nw_nfs_server\n" +
+      "  -4  Domain IPv4 address                      nw_ip\n" +
+      "  -g  Domain gateway                           nw_gw\n" +
+      "  -m  Domain net mask                          nw_mask\n" +
+      "  -h  Domain hostname                          nw_host\n" +
+      "\n" +
+      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
+      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
+      "domain 1 patterns would expand as follows:\n" +
+      "\n" +
+      "  /dev/hda+       /dev/hda1\n" +
+      "  /dev/hda7+      /dev/hda8\n" +
+      "  128.232.8.50+   128.232.8.51\n" +
+      "\n" +
+      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
+      "expanded to the corresponding setting from the calling domain.\n";
+  }
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java
new file mode 100644 (file)
index 0000000..b615907
--- /dev/null
@@ -0,0 +1,40 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.Command;
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandDomainStart;
+import org.xenoserver.control.Defaults;
+
+public class ParseDomainStart extends CommandParser {
+
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    int domain_id = getIntParameter(args, 'n', 0);
+    
+    if (domain_id == 0) {
+      throw new ParseFailedException("Expected -n<domain_id>");
+    }
+
+    String output = new CommandDomainStart(d, domain_id).execute();
+    if ( output != null )
+      System.out.println( output );
+  }
+
+  public String getName()
+  {
+    return "start";
+  }
+
+  public String getUsage()
+  {
+    return "[-n<domain_id>]";
+  }
+
+  public String getHelpText()
+  {
+    return
+      "Start the specified domain.";
+  }
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java
new file mode 100644 (file)
index 0000000..40bc152
--- /dev/null
@@ -0,0 +1,40 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.Command;
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandDomainStop;
+import org.xenoserver.control.Defaults;
+
+public class ParseDomainStop extends CommandParser {
+
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    int domain_id = getIntParameter(args, 'n', 0);
+    
+    if (domain_id == 0) {
+      throw new ParseFailedException("Expected -n<domain_id>");
+    }
+
+    String output = new CommandDomainStop(d, domain_id).execute();
+    if ( output != null )
+      System.out.println( output );
+  }
+
+  public String getName()
+  {
+    return "stop";
+  }
+
+  public String getUsage()
+  {
+    return "[-n<domain_id>]";
+  }
+
+  public String getHelpText()
+  {
+    return
+      "Stop the specified domain.";
+  }
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseGroup.java b/tools/control/src/org/xenoserver/cmdline/ParseGroup.java
new file mode 100644 (file)
index 0000000..1903dc4
--- /dev/null
@@ -0,0 +1,77 @@
+package org.xenoserver.cmdline;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.Defaults;
+
+public class ParseGroup extends CommandParser {
+  private final String name;
+  private final CommandParser[] commands;
+  
+  /**
+   * Constructor for ParseGroup.
+   * @param name Name of this group of commands
+   * @param commands Array of commands to include
+   */
+  public ParseGroup(String name, CommandParser[] commands) {
+    this.name = name;
+    this.commands = commands;
+  }
+
+  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
+    int i;
+    String c = (String) args.removeFirst();
+    for (i = 0; i < commands.length; i++) {
+      if (commands[i].getName().equals(c)) {
+        if (getFlagParameter(args, '?')) {
+          commands[i].printHelpText(null);
+        } else {
+          commands[i].parse(d, args);
+        }
+        break;
+      }
+    }
+    if (i == commands.length) {
+      throw new ParseFailedException("Unknown command " + c);
+    }
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public String getUsage() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public String getHelpText() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public void printUsage(String prefix) {
+    if ( prefix == null )
+      prefix = name;
+    else
+      prefix += " " + name;
+    for ( int i=0; i<commands.length; i++ )
+      commands[i].printUsage(prefix);
+  }
+
+  public void printHelpText(LinkedList args) {
+    if ( name != null )
+      System.out.print( name + " " );
+    int i;
+    String c = (String) args.removeFirst();
+    for (i = 0; i < commands.length; i++) {
+      if (commands[i].getName().equals(c)) {
+        commands[i].printHelpText(args);
+        break;
+      }
+    }
+  }
+}
index 0a8362e53db5bd20752f2b1c04fb4396d1a3453c..4d204c8ba4399b930f8c9d604ffa01ffddf9f463 100644 (file)
@@ -1,41 +1,25 @@
 package org.xenoserver.cmdline;
 
+import java.util.LinkedList;
+import java.util.List;
+
 import org.xenoserver.control.Command;
 import org.xenoserver.control.Defaults;
 
 public class ParseHelp extends CommandParser {
 
-  public void parse(Defaults d, String[] args) {
-    if (args.length <= 1) {
+  public void parse(Defaults d, LinkedList args) {
+    if (args.size() == 0) {
       System.out.println("Usage:");
-      for (int i = 0; i < Main.commands.length; i++) {
-        String name = Main.commands[i].getName();
-        String usage = Main.commands[i].getUsage();
-        while (name.length() < 12)
-          name = name + " ";
-        System.out.println("   " + name + usage);
-      }
+      Main.parser.printUsage(null);
     } else {
-      for (int i = 0; i < Main.commands.length; i++) {
-        String name = Main.commands[i].getName();
-        String usage = Main.commands[i].getUsage();
-        if (name.equals(args[1])) {
-          doHelpFor(Main.commands[i]);
-          break;
-        }
-      }
+      System.out.print("xenctl ");
+      Main.parser.printHelpText(args);
     }
 
     System.out.println("");
   }
   
-  public void doHelpFor(CommandParser c)
-  {
-    System.out.println ("xenctl " + c.getName() + " " + c.getUsage());
-    System.out.println ();
-    System.out.println (c.getHelpText ());
-  }
-
   public String getName()
   {
     return "help";
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseList.java b/tools/control/src/org/xenoserver/cmdline/ParseList.java
deleted file mode 100644 (file)
index 72d81c5..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.xenoserver.cmdline;
-
-import org.xenoserver.control.Command;
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandList;
-import org.xenoserver.control.Defaults;
-import org.xenoserver.control.Domain;
-
-public class ParseList extends CommandParser {
-
-  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
-    CommandList list = new CommandList(d);
-    String output = list.execute();
-    if ( output != null )
-      System.out.println( output );
-    Domain[] domains = list.domains();
-
-    for (int loop = 0; loop < domains.length; loop++)
-    {
-      System.out.println ("id: " + domains[loop].id + 
-        " (" + domains[loop].name+ ")");
-      System.out.println ("  processor: " + domains[loop].processor);
-      System.out.println ("  has cpu: " + domains[loop].cpu);
-      System.out.println ("  state: " + domains[loop].nstate + " " +
-        domains[loop].state);
-      System.out.println ("  mcu advance: " + domains[loop].mcu);
-      System.out.println ("  total pages: " + domains[loop].pages);
-    }
-  }
-
-  public String getName()
-  {
-    return "list";
-  }
-
-  public String getUsage()
-  {
-    return "";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "List domain information";
-  }
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseNew.java b/tools/control/src/org/xenoserver/cmdline/ParseNew.java
deleted file mode 100644 (file)
index 5ddfd7a..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.xenoserver.cmdline;
-
-import org.xenoserver.control.Command;
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandNew;
-import org.xenoserver.control.Defaults;
-
-public class ParseNew extends CommandParser {
-
-  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
-    String name = getStringParameter(args, 'n', d.domainName);
-    int size = getIntParameter(args, 'k', d.domainSizeKB);
-    String image = getStringParameter(args, 'i', d.domainImage);
-    String initrd = getStringParameter (args, 'r', d.domainInitRD);
-    int vifs = getIntParameter(args, 'v', d.domainVIFs);
-    String bargs = getStringParameter (args, 'a', d.args) + " ";
-    String root_dev = getStringParameter (args, 'd', d.rootDevice);
-    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
-    String nw_ip = getStringParameter (args, '4', d.NWIP);
-    String nw_gw = getStringParameter (args, 'g', d.NWGW);
-    String nw_mask = getStringParameter (args, 'm', d.NWMask);
-    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
-    String nw_host = getStringParameter (args, 'h', d.NWHost);
-
-    d.describe();
-
-    CommandNew c = new CommandNew(d, name, size, image, initrd, vifs,
-                                  bargs, root_dev, nfs_root_path,
-                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
-    c.execute();
-    String[] output = c.output();
-    for ( int i = 0; i < output.length; i++ )
-      System.out.println( output[i] ); 
-  }
-
-  public String getName()
-  {
-    return "new";
-  }
-
-  public String getUsage()
-  {
-    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Create a new domain.  Note that most of the parameters will assume\n" +
-      "default values: it should not be necessary to specify them all. See\n" +
-      "domctl.xml for the current default settings.\n" +
-      "\n" +
-      "General command line options:\n" +
-      "  -n  Domain name                              domain_name\n" +
-      "  -k  Domain size (kb)                         domain_size_kb\n" +
-      "  -i  Domain image name                        domain_image\n" +
-      "  -v  Number of VIFs                           domain_vifs\n" +
-      "  -r  InitRD (if required)                     domain_init_rd\n" +
-      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
-      "  -a  Additional boot parameters\n" +
-      "\n" +
-      "Networking options:\n" +
-      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
-      "  -s  NFS server                               nw_nfs_server\n" +
-      "  -4  Domain IPv4 address                      nw_ip\n" +
-      "  -g  Domain gateway                           nw_gw\n" +
-      "  -m  Domain net mask                          nw_mask\n" +
-      "  -h  Domain hostname                          nw_host\n" +
-      "\n" +
-      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
-      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
-      "domain 1 patterns would expand as follows:\n" +
-      "\n" +
-      "  /dev/hda+       /dev/hda1\n" +
-      "  /dev/hda7+      /dev/hda8\n" +
-      "  128.232.8.50+   128.232.8.51\n" +
-      "\n" +
-      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
-      "expanded to the corresponding setting from the calling domain.\n";
-  }
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseStart.java b/tools/control/src/org/xenoserver/cmdline/ParseStart.java
deleted file mode 100644 (file)
index 435e36a..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.xenoserver.cmdline;
-
-import org.xenoserver.control.Command;
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandStart;
-import org.xenoserver.control.Defaults;
-
-public class ParseStart extends CommandParser {
-
-  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
-    }
-
-    String output = new CommandStart(d, domain_id).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-
-  public String getName()
-  {
-    return "start";
-  }
-
-  public String getUsage()
-  {
-    return "[-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Start the specified domain.";
-  }
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseStop.java b/tools/control/src/org/xenoserver/cmdline/ParseStop.java
deleted file mode 100644 (file)
index 30aeadb..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.xenoserver.cmdline;
-
-import org.xenoserver.control.Command;
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandStop;
-import org.xenoserver.control.Defaults;
-
-public class ParseStop extends CommandParser {
-
-  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
-    }
-
-    String output = new CommandStop(d, domain_id).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-
-  public String getName()
-  {
-    return "stop";
-  }
-
-  public String getUsage()
-  {
-    return "[-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Stop the specified domain.";
-  }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandDestroy.java b/tools/control/src/org/xenoserver/control/CommandDestroy.java
deleted file mode 100644 (file)
index bc1f65e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Destroys a domain.
- */
-public class CommandDestroy extends Command {
-  private Defaults d;
-  private int domain_id;
-  private boolean force;
-
-  /**
-   * Constructor for CommandDestroy.
-   * 
-   * @param d Defaults object to use.
-   * @param domain_id Domain ID number to destroy.
-   * @param force Force destruction.
-   */
-  public CommandDestroy(Defaults d, int domain_id, boolean force) {
-    this.d = d;
-    this.domain_id = domain_id;
-    this.force = force;
-  }
-
-  public String execute() throws CommandFailedException {
-    Runtime r = Runtime.getRuntime();
-    String output = null;
-
-    try {
-      Process destroy_p;
-      String destroy_cmdarray[] = force ? new String[3] : new String[2];
-      int destroy_rc;
-      int idx = 0;
-      destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
-      if (force) {
-        destroy_cmdarray[idx++] = "-f";
-      }
-      destroy_cmdarray[idx++] = "" + domain_id;
-
-      if (Settings.TEST) {
-        output = reportCommand(destroy_cmdarray);
-      } else {
-        destroy_p = r.exec(destroy_cmdarray);
-        destroy_rc = destroy_p.waitFor();
-
-        if (destroy_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray);
-        }
-        output = "Destroyed domain " + domain_id;
-      }
-    } catch (CommandFailedException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CommandFailedException("Could not destroy domain (" + e + ")", e);
-    }
-
-    return output;
-  }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java b/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java
new file mode 100644 (file)
index 0000000..6bb6616
--- /dev/null
@@ -0,0 +1,58 @@
+package org.xenoserver.control;
+
+/**
+ * Destroys a domain.
+ */
+public class CommandDomainDestroy extends Command {
+  private Defaults d;
+  private int domain_id;
+  private boolean force;
+
+  /**
+   * Constructor for CommandDomainDestroy.
+   * 
+   * @param d Defaults object to use.
+   * @param domain_id Domain ID number to destroy.
+   * @param force Force destruction.
+   */
+  public CommandDomainDestroy(Defaults d, int domain_id, boolean force) {
+    this.d = d;
+    this.domain_id = domain_id;
+    this.force = force;
+  }
+
+  public String execute() throws CommandFailedException {
+    Runtime r = Runtime.getRuntime();
+    String output = null;
+
+    try {
+      Process destroy_p;
+      String destroy_cmdarray[] = force ? new String[3] : new String[2];
+      int destroy_rc;
+      int idx = 0;
+      destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
+      if (force) {
+        destroy_cmdarray[idx++] = "-f";
+      }
+      destroy_cmdarray[idx++] = "" + domain_id;
+
+      if (Settings.TEST) {
+        output = reportCommand(destroy_cmdarray);
+      } else {
+        destroy_p = r.exec(destroy_cmdarray);
+        destroy_rc = destroy_p.waitFor();
+
+        if (destroy_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray);
+        }
+        output = "Destroyed domain " + domain_id;
+      }
+    } catch (CommandFailedException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new CommandFailedException("Could not destroy domain (" + e + ")", e);
+    }
+
+    return output;
+  }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandDomainList.java b/tools/control/src/org/xenoserver/control/CommandDomainList.java
new file mode 100644 (file)
index 0000000..39ccd38
--- /dev/null
@@ -0,0 +1,108 @@
+package org.xenoserver.control;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * Lists details of all domains. After execute() has been called, call
+ * domains() to get the array of domains.
+ */
+public class CommandDomainList extends Command {
+  private Defaults d;
+  private Domain[] array;
+
+  /**
+   * Constructor for CommandDomainList.
+   * @param d Defaults object to use.
+   */
+  public CommandDomainList(Defaults d) {
+    this.d = d;
+  }
+
+  /**
+   * Retrieves the list of domains.
+   * @return null, call domains() to get the list.
+   */
+  public String execute() throws CommandFailedException {
+    Runtime r = Runtime.getRuntime();
+    int rc = 0;
+    Vector v = new Vector();
+    String outline;
+    BufferedReader in;
+    String output = null;
+
+    try {
+      Process start_p;
+      String start_cmdarray[] = new String[1];
+      int start_rc;
+      start_cmdarray[0] = d.XIToolsDir + "xi_list";
+
+      if (Settings.TEST) {
+        output = reportCommand(start_cmdarray);
+      } else {
+        start_p = r.exec(start_cmdarray);
+        start_rc = start_p.waitFor();
+        if (start_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray);
+        }
+
+        in =
+          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
+
+        outline = in.readLine();
+        while (outline != null) {
+          Domain domain = new Domain();
+
+          StringTokenizer st = new StringTokenizer(outline);
+          if (st.hasMoreTokens()) {
+            domain.id = Integer.parseInt(st.nextToken());
+          }
+          if (st.hasMoreTokens()) {
+            domain.processor = Integer.parseInt(st.nextToken());
+          }
+          if (st.hasMoreTokens()) {
+            if (st.nextToken().equals("1")) {
+              domain.cpu = true;
+            } else {
+              domain.cpu = false;
+            }
+          }
+          if (st.hasMoreTokens()) {
+            domain.nstate = Integer.parseInt(st.nextToken());
+          }
+          if (st.hasMoreTokens()) {
+            domain.state = st.nextToken().toLowerCase();
+          }
+          if (st.hasMoreTokens()) {
+            domain.mcu = Integer.parseInt(st.nextToken());
+          }
+          if (st.hasMoreTokens()) {
+            domain.pages = Integer.parseInt(st.nextToken());
+          }
+          if (st.hasMoreTokens()) {
+            domain.name = st.nextToken();
+          }
+
+          v.add(domain);
+
+          outline = in.readLine();
+        }
+
+      }
+    } catch (CommandFailedException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new CommandFailedException("Could not get domain list(" + e + ")", e);
+    }
+
+    array = new Domain[v.size()];
+    v.toArray(array);
+    return output;
+  }
+  
+  public Domain[] domains() {
+    return array;
+  }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandDomainNew.java b/tools/control/src/org/xenoserver/control/CommandDomainNew.java
new file mode 100644 (file)
index 0000000..50fa6da
--- /dev/null
@@ -0,0 +1,301 @@
+package org.xenoserver.control;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * Creates a new domain. As this command returns a multi-line result,
+ * call output() to get an array of strings.
+ */
+public class CommandDomainNew extends Command {
+  private Defaults d;
+  private String name;
+  private int size;
+  private String image;
+  private String initrd;
+  private int vifs;
+  private String bargs;
+  private String root_dev;
+  private String nfs_root_path;
+  private String nw_ip;
+  private String nw_gw;
+  private String nw_mask;
+  private String nw_nfs_server;
+  private String nw_host;
+  private String[] output;
+  
+  public String[] output() {
+    return output;
+  }
+  
+  /**
+   * Constructor for CommandDomainNew.
+   * @param d Defaults object to use.
+   * @param name Name for the domain.
+   * @param size Memory size for the domain.
+   * @param image Image to boot domain from.
+   * @param initrd Initrd to boot domain with.
+   * @param vifs Number of virtual interfaces for the domain.
+   * @param bargs Boot arguments for the domain.
+   * @param root_dev Root device for the domain.
+   * @param nfs_root_path NFS root to be used by the domain.
+   * @param nw_ip IP address pattern to use for the domain's interfaces.
+   * @param nw_gw Gateway to configure the domain for.
+   * @param nw_mask Network mask to configure the domain for.
+   * @param nw_nfs_server NFS server to be used by the domain.
+   * @param nw_host Hostname to be used by the domain.
+   */
+  public CommandDomainNew(
+    Defaults d,
+    String name,
+    int size,
+    String image,
+    String initrd,
+    int vifs,
+    String bargs,
+    String root_dev,
+    String nfs_root_path,
+    String nw_ip,
+    String nw_gw,
+    String nw_mask,
+    String nw_nfs_server,
+    String nw_host) {
+    this.d = d;
+    this.name = name;
+    this.size = size;
+    this.image = image;
+    this.initrd = initrd;
+    this.vifs = vifs;
+    this.bargs = bargs;
+    this.root_dev = root_dev;
+    this.nfs_root_path = nfs_root_path;
+    this.nw_ip = nw_ip;
+    this.nw_gw = nw_gw;
+    this.nw_mask = nw_mask;
+    this.nw_nfs_server = nw_nfs_server;
+    this.nw_host = nw_host;
+  }
+
+  public String execute() throws CommandFailedException {
+    Runtime r = Runtime.getRuntime();
+    int domain_id = -1;
+    BufferedReader br;
+    int idx;
+    int i;
+    File image_tmp = null;
+    File initrd_tmp = null;
+    String domain_ip = "";
+    
+    String create_cmdarray[] = new String[3];
+    String build_cmdarray[] = new String[6];
+    String vifinit_cmdarray[] = new String[4];
+
+    try {
+      try {
+        /* Some initial sanity checks */
+        if (root_dev.equals("/dev/nfs") && (vifs == 0)) {
+          throw new CommandFailedException("Cannot use NFS root without VIFs configured");
+        }
+
+        /* Uncompress the image and initrd */
+        if (image.endsWith(".gz")) {
+          image_tmp = getUncompressed("xen-image-", image);
+          image = image_tmp.getPath();
+        }
+
+        if (initrd != null && initrd.endsWith(".gz")) {
+          initrd_tmp = getUncompressed("xen-initrd-", initrd);
+          initrd = initrd_tmp.getPath();
+        }
+
+        /* Create a new empty domain */
+        Process create_p;
+        int create_rc;
+        create_cmdarray[0] = d.XIToolsDir + "xi_create";
+        create_cmdarray[1] = "" + size;
+        create_cmdarray[2] = name;
+        if (Settings.TEST) {
+          reportCommand(create_cmdarray);
+          domain_id = 1;
+          create_rc = 0;
+        } else {
+          create_p = r.exec(create_cmdarray);
+          br =
+            new BufferedReader(
+              new InputStreamReader(create_p.getInputStream()));
+          domain_id = Integer.parseInt(br.readLine());
+          create_rc = create_p.waitFor();
+        }
+
+        if (create_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray);
+        } else if (domain_id > d.MaxDomainNumber) {
+          throw new CommandFailedException(
+            "Cannot configure more than " + d.MaxDomainNumber + " domains");
+        }
+
+        /* Set up boot parameters to pass to xi_build. */
+        if (root_dev.equals("/dev/nfs")) {
+          if (vifs == 0) {
+            throw new CommandFailedException("Cannot use NFS root without VIFs configured");
+          }
+          if (nfs_root_path == null) {
+            throw new CommandFailedException("No NFS root specified");
+          }
+          if (nw_nfs_server == null) {
+            throw new CommandFailedException("No NFS server specified");
+          }
+          bargs =
+            (bargs
+              + " root=/dev/nfs "
+              + "nfsroot="
+              + StringPattern.parse(nfs_root_path).resolve(domain_id)
+              + " ");
+        } else {
+          bargs =
+            (bargs
+              + " root="
+              + StringPattern.parse(root_dev).resolve(domain_id)
+              + " ");
+
+        }
+
+        if (vifs > 0) {
+          domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
+          if (nw_host == null) {
+            try {
+              nw_host = InetAddress.getByName(domain_ip).getHostName();
+            } catch (UnknownHostException uhe) {
+              nw_host = "" + nw_ip;
+            }
+
+          }
+          bargs =
+            ("ip="
+              + domain_ip
+              + ":"
+              + ((nw_nfs_server == null)
+                ? ""
+                : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id)))
+              + ":"
+              + ((nw_gw == null)
+                ? ""
+                : (InetAddressPattern.parse(nw_gw).resolve(domain_id)))
+              + ":"
+              + ((nw_mask == null)
+                ? ""
+                : InetAddressPattern.parse(nw_mask).resolve(domain_id))
+              + ":"
+              + ((nw_host == null) ? "" : nw_host)
+              + ":eth0:off "
+              + bargs);
+        }
+
+        /* Build the domain */
+        Process build_p;
+        int build_rc;
+        idx = 0;
+        for (i = 0; i < build_cmdarray.length; i++)
+          build_cmdarray[i] = "";
+        build_cmdarray[idx++] = d.XIToolsDir + "xi_build";
+        build_cmdarray[idx++] = "" + domain_id;
+        build_cmdarray[idx++] = "" + image;
+        build_cmdarray[idx++] = "" + vifs;
+        if (initrd != null)
+          build_cmdarray[idx++] = "initrd=" + initrd;
+        build_cmdarray[idx++] = "" + bargs;
+        if (Settings.TEST) {
+          reportCommand(build_cmdarray);
+          build_rc = 0;
+        } else {
+          build_p = r.exec(build_cmdarray);
+          build_rc = build_p.waitFor();
+        }
+
+        if (build_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray);
+        }
+
+        /* Set up the first VIF if necessary */
+        if (vifs > 0) {
+          Process vifinit_p;
+          int vifinit_rc;
+          vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
+          vifinit_cmdarray[1] = "" + domain_id;
+          vifinit_cmdarray[2] = "0";
+          vifinit_cmdarray[3] = domain_ip;
+          if (Settings.TEST) {
+            reportCommand(vifinit_cmdarray);
+            vifinit_rc = 0;
+          } else {
+            vifinit_p = r.exec(vifinit_cmdarray);
+            vifinit_rc = vifinit_p.waitFor();
+          }
+
+          if (vifinit_rc != 0) {
+            throw CommandFailedException.XICommandFailed(
+              "Failed to initialise VIF 0",
+              vifinit_cmdarray);
+          }
+        }
+      } finally {
+        if (image_tmp != null)
+          image_tmp.delete();
+        if (initrd_tmp != null)
+          initrd_tmp.delete();
+      }
+    } catch (CommandFailedException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new CommandFailedException("Could not create new domain (" + e + ")", e);
+    }
+
+    output = new String[ vifs > 0 ? 6 : 4 ];
+    output[0] = "Domain created with arguments:";
+    output[1] = "";
+    for (i = 0; i < create_cmdarray.length; i++)
+      output[1] += create_cmdarray[i] + " ";
+    output[2] = "Domain built with arguments:";
+    output[3] = "";
+    for (i = 0; i < build_cmdarray.length; i++)
+      output[3] += build_cmdarray[i] + " ";
+    if ( vifs > 0 ) {
+      output[4] = "VIF 0 initialized with arguments:";
+      output[5] = "";
+      for (i = 0; i < vifinit_cmdarray.length; i++)
+        output[5] += vifinit_cmdarray[i] + " ";
+    }
+
+    return null;
+  }
+  
+  private File getUncompressed (String prefix, String original) throws IOException {
+    FileOutputStream fos;
+    GZIPInputStream gis;
+    File result;
+    byte buffer[] = new byte[1024];
+    int l;
+    
+    result = File.createTempFile (prefix, null);
+    
+    try {
+      fos = new FileOutputStream (result);
+      gis = new GZIPInputStream (new FileInputStream (original));
+      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
+  fos.write (buffer, 0, l);
+      }   
+    } catch (IOException ioe) {
+      result.delete ();
+      throw ioe;
+    }
+
+    return result;
+  }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandDomainStart.java b/tools/control/src/org/xenoserver/control/CommandDomainStart.java
new file mode 100644 (file)
index 0000000..1719da2
--- /dev/null
@@ -0,0 +1,49 @@
+package org.xenoserver.control;
+
+/**
+ * Starts a domain.
+ */
+public class CommandDomainStart extends Command {
+  private Defaults d;
+  private int domain_id;
+  
+  /**
+   * Constructor for CommandDomainStart.
+   * @param d Defaults object to use.
+   * @param domain_id Domain to start.
+   */
+  public CommandDomainStart(Defaults d, int domain_id) {
+    this.d = d;
+    this.domain_id = domain_id;
+  }
+
+  public String execute() throws CommandFailedException {
+    Runtime r = Runtime.getRuntime();
+    String output = null;
+
+    try {
+      Process start_p;
+      String start_cmdarray[] = new String[2];
+      int start_rc;
+      start_cmdarray[0] = d.XIToolsDir + "xi_start";
+      start_cmdarray[1] = "" + domain_id;
+
+      if (Settings.TEST) {
+        output = reportCommand(start_cmdarray);
+      } else {
+        start_p = r.exec(start_cmdarray);
+        start_rc = start_p.waitFor();
+        if (start_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray);
+        }
+        output = "Started domain " + domain_id;
+      }
+    } catch (CommandFailedException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new CommandFailedException("Could not start new domain (" + e + ")", e);
+    }
+
+    return output;
+  }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandDomainStop.java b/tools/control/src/org/xenoserver/control/CommandDomainStop.java
new file mode 100644 (file)
index 0000000..b66fae6
--- /dev/null
@@ -0,0 +1,50 @@
+package org.xenoserver.control;
+
+/**
+ * Stops a domain.
+ */
+public class CommandDomainStop extends Command {
+  private Defaults d;
+  private int domain_id;
+  
+  /**
+   * Constructor for CommandDomainStop.
+   * @param d The defaults object to use.
+   * @param domain_id The domain to stop.
+   */
+  public CommandDomainStop(Defaults d, int domain_id) {
+    this.d = d;
+    this.domain_id = domain_id;
+  }
+
+  public String execute() throws CommandFailedException {
+    Runtime r = Runtime.getRuntime();
+    String output = null;
+
+    try {
+      Process stop_p;
+      String stop_cmdarray[] = new String[2];
+      int stop_rc;
+      stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
+      stop_cmdarray[1] = "" + domain_id;
+
+      if (Settings.TEST) {
+        output = reportCommand(stop_cmdarray);
+      } else {
+        stop_p = r.exec(stop_cmdarray);
+        stop_rc = stop_p.waitFor();
+
+        if (stop_rc != 0) {
+          throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray);
+        }
+        output = "Stopped domain " + domain_id;
+      }
+    } catch (CommandFailedException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new CommandFailedException("Could not stop new domain (" + e + ")", e);
+    }
+
+    return output;
+  }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandList.java b/tools/control/src/org/xenoserver/control/CommandList.java
deleted file mode 100644 (file)
index af26225..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.xenoserver.control;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-/**
- * Lists details of all domains. After execute() has been called, call
- * domains() to get the array of domains.
- */
-public class CommandList extends Command {
-  private Defaults d;
-  private Domain[] array;
-
-  /**
-   * Constructor for CommandList.
-   * @param d Defaults object to use.
-   */
-  public CommandList(Defaults d) {
-    this.d = d;
-  }
-
-  /**
-   * Retrieves the list of domains.
-   * @return null, call domains() to get the list.
-   */
-  public String execute() throws CommandFailedException {
-    Runtime r = Runtime.getRuntime();
-    int rc = 0;
-    Vector v = new Vector();
-    String outline;
-    BufferedReader in;
-    String output = null;
-
-    try {
-      Process start_p;
-      String start_cmdarray[] = new String[1];
-      int start_rc;
-      start_cmdarray[0] = d.XIToolsDir + "xi_list";
-
-      if (Settings.TEST) {
-        output = reportCommand(start_cmdarray);
-      } else {
-        start_p = r.exec(start_cmdarray);
-        start_rc = start_p.waitFor();
-        if (start_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray);
-        }
-
-        in =
-          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
-
-        outline = in.readLine();
-        while (outline != null) {
-          Domain domain = new Domain();
-
-          StringTokenizer st = new StringTokenizer(outline);
-          if (st.hasMoreTokens()) {
-            domain.id = Integer.parseInt(st.nextToken());
-          }
-          if (st.hasMoreTokens()) {
-            domain.processor = Integer.parseInt(st.nextToken());
-          }
-          if (st.hasMoreTokens()) {
-            if (st.nextToken().equals("1")) {
-              domain.cpu = true;
-            } else {
-              domain.cpu = false;
-            }
-          }
-          if (st.hasMoreTokens()) {
-            domain.nstate = Integer.parseInt(st.nextToken());
-          }
-          if (st.hasMoreTokens()) {
-            domain.state = st.nextToken().toLowerCase();
-          }
-          if (st.hasMoreTokens()) {
-            domain.mcu = Integer.parseInt(st.nextToken());
-          }
-          if (st.hasMoreTokens()) {
-            domain.pages = Integer.parseInt(st.nextToken());
-          }
-          if (st.hasMoreTokens()) {
-            domain.name = st.nextToken();
-          }
-
-          v.add(domain);
-
-          outline = in.readLine();
-        }
-
-      }
-    } catch (CommandFailedException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CommandFailedException("Could not get domain list(" + e + ")", e);
-    }
-
-    array = new Domain[v.size()];
-    v.toArray(array);
-    return output;
-  }
-  
-  public Domain[] domains() {
-    return array;
-  }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandNew.java b/tools/control/src/org/xenoserver/control/CommandNew.java
deleted file mode 100644 (file)
index 4f32e97..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-package org.xenoserver.control;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.zip.GZIPInputStream;
-
-/**
- * Creates a new domain. As this command returns a multi-line result,
- * call output() to get an array of strings.
- */
-public class CommandNew extends Command {
-  private Defaults d;
-  private String name;
-  private int size;
-  private String image;
-  private String initrd;
-  private int vifs;
-  private String bargs;
-  private String root_dev;
-  private String nfs_root_path;
-  private String nw_ip;
-  private String nw_gw;
-  private String nw_mask;
-  private String nw_nfs_server;
-  private String nw_host;
-  private String[] output;
-  
-  public String[] output() {
-    return output;
-  }
-  
-  /**
-   * Constructor for CommandNew.
-   * @param d Defaults object to use.
-   * @param name Name for the domain.
-   * @param size Memory size for the domain.
-   * @param image Image to boot domain from.
-   * @param initrd Initrd to boot domain with.
-   * @param vifs Number of virtual interfaces for the domain.
-   * @param bargs Boot arguments for the domain.
-   * @param root_dev Root device for the domain.
-   * @param nfs_root_path NFS root to be used by the domain.
-   * @param nw_ip IP address pattern to use for the domain's interfaces.
-   * @param nw_gw Gateway to configure the domain for.
-   * @param nw_mask Network mask to configure the domain for.
-   * @param nw_nfs_server NFS server to be used by the domain.
-   * @param nw_host Hostname to be used by the domain.
-   */
-  public CommandNew(
-    Defaults d,
-    String name,
-    int size,
-    String image,
-    String initrd,
-    int vifs,
-    String bargs,
-    String root_dev,
-    String nfs_root_path,
-    String nw_ip,
-    String nw_gw,
-    String nw_mask,
-    String nw_nfs_server,
-    String nw_host) {
-    this.d = d;
-    this.name = name;
-    this.size = size;
-    this.image = image;
-    this.initrd = initrd;
-    this.vifs = vifs;
-    this.bargs = bargs;
-    this.root_dev = root_dev;
-    this.nfs_root_path = nfs_root_path;
-    this.nw_ip = nw_ip;
-    this.nw_gw = nw_gw;
-    this.nw_mask = nw_mask;
-    this.nw_nfs_server = nw_nfs_server;
-    this.nw_host = nw_host;
-  }
-
-  public String execute() throws CommandFailedException {
-    Runtime r = Runtime.getRuntime();
-    int domain_id = -1;
-    BufferedReader br;
-    int idx;
-    int i;
-    File image_tmp = null;
-    File initrd_tmp = null;
-    String domain_ip = "";
-    
-    String create_cmdarray[] = new String[3];
-    String build_cmdarray[] = new String[6];
-    String vifinit_cmdarray[] = new String[4];
-
-    try {
-      try {
-        /* Some initial sanity checks */
-        if (root_dev.equals("/dev/nfs") && (vifs == 0)) {
-          throw new CommandFailedException("Cannot use NFS root without VIFs configured");
-        }
-
-        /* Uncompress the image and initrd */
-        if (image.endsWith(".gz")) {
-          image_tmp = getUncompressed("xen-image-", image);
-          image = image_tmp.getPath();
-        }
-
-        if (initrd != null && initrd.endsWith(".gz")) {
-          initrd_tmp = getUncompressed("xen-initrd-", initrd);
-          initrd = initrd_tmp.getPath();
-        }
-
-        /* Create a new empty domain */
-        Process create_p;
-        int create_rc;
-        create_cmdarray[0] = d.XIToolsDir + "xi_create";
-        create_cmdarray[1] = "" + size;
-        create_cmdarray[2] = name;
-        if (Settings.TEST) {
-          reportCommand(create_cmdarray);
-          domain_id = 1;
-          create_rc = 0;
-        } else {
-          create_p = r.exec(create_cmdarray);
-          br =
-            new BufferedReader(
-              new InputStreamReader(create_p.getInputStream()));
-          domain_id = Integer.parseInt(br.readLine());
-          create_rc = create_p.waitFor();
-        }
-
-        if (create_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray);
-        } else if (domain_id > d.MaxDomainNumber) {
-          throw new CommandFailedException(
-            "Cannot configure more than " + d.MaxDomainNumber + " domains");
-        }
-
-        /* Set up boot parameters to pass to xi_build. */
-        if (root_dev.equals("/dev/nfs")) {
-          if (vifs == 0) {
-            throw new CommandFailedException("Cannot use NFS root without VIFs configured");
-          }
-          if (nfs_root_path == null) {
-            throw new CommandFailedException("No NFS root specified");
-          }
-          if (nw_nfs_server == null) {
-            throw new CommandFailedException("No NFS server specified");
-          }
-          bargs =
-            (bargs
-              + " root=/dev/nfs "
-              + "nfsroot="
-              + StringPattern.parse(nfs_root_path).resolve(domain_id)
-              + " ");
-        } else {
-          bargs =
-            (bargs
-              + " root="
-              + StringPattern.parse(root_dev).resolve(domain_id)
-              + " ");
-
-        }
-
-        if (vifs > 0) {
-          domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
-          if (nw_host == null) {
-            try {
-              nw_host = InetAddress.getByName(domain_ip).getHostName();
-            } catch (UnknownHostException uhe) {
-              nw_host = "" + nw_ip;
-            }
-
-          }
-          bargs =
-            ("ip="
-              + domain_ip
-              + ":"
-              + ((nw_nfs_server == null)
-                ? ""
-                : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id)))
-              + ":"
-              + ((nw_gw == null)
-                ? ""
-                : (InetAddressPattern.parse(nw_gw).resolve(domain_id)))
-              + ":"
-              + ((nw_mask == null)
-                ? ""
-                : InetAddressPattern.parse(nw_mask).resolve(domain_id))
-              + ":"
-              + ((nw_host == null) ? "" : nw_host)
-              + ":eth0:off "
-              + bargs);
-        }
-
-        /* Build the domain */
-        Process build_p;
-        int build_rc;
-        idx = 0;
-        for (i = 0; i < build_cmdarray.length; i++)
-          build_cmdarray[i] = "";
-        build_cmdarray[idx++] = d.XIToolsDir + "xi_build";
-        build_cmdarray[idx++] = "" + domain_id;
-        build_cmdarray[idx++] = "" + image;
-        build_cmdarray[idx++] = "" + vifs;
-        if (initrd != null)
-          build_cmdarray[idx++] = "initrd=" + initrd;
-        build_cmdarray[idx++] = "" + bargs;
-        if (Settings.TEST) {
-          reportCommand(build_cmdarray);
-          build_rc = 0;
-        } else {
-          build_p = r.exec(build_cmdarray);
-          build_rc = build_p.waitFor();
-        }
-
-        if (build_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray);
-        }
-
-        /* Set up the first VIF if necessary */
-        if (vifs > 0) {
-          Process vifinit_p;
-          int vifinit_rc;
-          vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
-          vifinit_cmdarray[1] = "" + domain_id;
-          vifinit_cmdarray[2] = "0";
-          vifinit_cmdarray[3] = domain_ip;
-          if (Settings.TEST) {
-            reportCommand(vifinit_cmdarray);
-            vifinit_rc = 0;
-          } else {
-            vifinit_p = r.exec(vifinit_cmdarray);
-            vifinit_rc = vifinit_p.waitFor();
-          }
-
-          if (vifinit_rc != 0) {
-            throw CommandFailedException.XICommandFailed(
-              "Failed to initialise VIF 0",
-              vifinit_cmdarray);
-          }
-        }
-      } finally {
-        if (image_tmp != null)
-          image_tmp.delete();
-        if (initrd_tmp != null)
-          initrd_tmp.delete();
-      }
-    } catch (CommandFailedException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CommandFailedException("Could not create new domain (" + e + ")", e);
-    }
-
-    output = new String[ vifs > 0 ? 6 : 4 ];
-    output[0] = "Domain created with arguments:";
-    output[1] = "";
-    for (i = 0; i < create_cmdarray.length; i++)
-      output[1] += create_cmdarray[i] + " ";
-    output[2] = "Domain built with arguments:";
-    output[3] = "";
-    for (i = 0; i < build_cmdarray.length; i++)
-      output[3] += build_cmdarray[i] + " ";
-    if ( vifs > 0 ) {
-      output[4] = "VIF 0 initialized with arguments:";
-      output[5] = "";
-      for (i = 0; i < vifinit_cmdarray.length; i++)
-        output[5] += vifinit_cmdarray[i] + " ";
-    }
-
-    return null;
-  }
-  
-  private File getUncompressed (String prefix, String original) throws IOException {
-    FileOutputStream fos;
-    GZIPInputStream gis;
-    File result;
-    byte buffer[] = new byte[1024];
-    int l;
-    
-    result = File.createTempFile (prefix, null);
-    
-    try {
-      fos = new FileOutputStream (result);
-      gis = new GZIPInputStream (new FileInputStream (original));
-      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
-  fos.write (buffer, 0, l);
-      }   
-    } catch (IOException ioe) {
-      result.delete ();
-      throw ioe;
-    }
-
-    return result;
-  }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandStart.java b/tools/control/src/org/xenoserver/control/CommandStart.java
deleted file mode 100644 (file)
index 7722ccd..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Starts a domain.
- */
-public class CommandStart extends Command {
-  private Defaults d;
-  private int domain_id;
-  
-  /**
-   * Constructor for CommandStart.
-   * @param d Defaults object to use.
-   * @param domain_id Domain to start.
-   */
-  public CommandStart(Defaults d, int domain_id) {
-    this.d = d;
-    this.domain_id = domain_id;
-  }
-
-  public String execute() throws CommandFailedException {
-    Runtime r = Runtime.getRuntime();
-    String output = null;
-
-    try {
-      Process start_p;
-      String start_cmdarray[] = new String[2];
-      int start_rc;
-      start_cmdarray[0] = d.XIToolsDir + "xi_start";
-      start_cmdarray[1] = "" + domain_id;
-
-      if (Settings.TEST) {
-        output = reportCommand(start_cmdarray);
-      } else {
-        start_p = r.exec(start_cmdarray);
-        start_rc = start_p.waitFor();
-        if (start_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray);
-        }
-        output = "Started domain " + domain_id;
-      }
-    } catch (CommandFailedException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CommandFailedException("Could not start new domain (" + e + ")", e);
-    }
-
-    return output;
-  }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandStop.java b/tools/control/src/org/xenoserver/control/CommandStop.java
deleted file mode 100644 (file)
index d280875..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Stops a domain.
- */
-public class CommandStop extends Command {
-  private Defaults d;
-  private int domain_id;
-  
-  /**
-   * Constructor for CommandStop.
-   * @param d The defaults object to use.
-   * @param domain_id The domain to stop.
-   */
-  public CommandStop(Defaults d, int domain_id) {
-    this.d = d;
-    this.domain_id = domain_id;
-  }
-
-  public String execute() throws CommandFailedException {
-    Runtime r = Runtime.getRuntime();
-    String output = null;
-
-    try {
-      Process stop_p;
-      String stop_cmdarray[] = new String[2];
-      int stop_rc;
-      stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
-      stop_cmdarray[1] = "" + domain_id;
-
-      if (Settings.TEST) {
-        output = reportCommand(stop_cmdarray);
-      } else {
-        stop_p = r.exec(stop_cmdarray);
-        stop_rc = stop_p.waitFor();
-
-        if (stop_rc != 0) {
-          throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray);
-        }
-        output = "Stopped domain " + domain_id;
-      }
-    } catch (CommandFailedException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CommandFailedException("Could not stop new domain (" + e + ")", e);
-    }
-
-    return output;
-  }
-}